package com.wyp168.jvm001;

/**
 * @ClassName ClassLoaderDemo002
 * @Description TODO
 * @Author wyp168
 * @Date 2022/7/20 15:22
 */
public class ClassLoaderDemo002 {
    public static void main(String[] args) {
        //获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); //sun.misc.Launcher$AppClassLoader@18b4aac2
        System.out.println(systemClassLoader);
    
        //获取系统类加载器的上层加载器（加载器是包含关系）：扩展类加载器
        ClassLoader extClassLoader = systemClassLoader.getParent();
        System.out.println(extClassLoader); //sun.misc.Launcher$ExtClassLoader@232204a1

        //尝试获取扩展类加载器的上层加载器：获取不到（引导类加载器）
        ClassLoader bootstrapClassLoader = extClassLoader.getParent();  //null
        System.out.println(bootstrapClassLoader);

        //打印当前类被哪个加载器加载: 系统类加载器
        ClassLoader classLoader = ClassLoaderDemo002.class.getClassLoader();    //sun.misc.Launcher$AppClassLoader@18b4aac2
        System.out.println(classLoader);

        //打印String类被哪个加载器加载：引导类加载器
        ClassLoader stringClassLoader = String.class.getClassLoader();  //null
        System.out.println(stringClassLoader);
    }
}
